<?php

namespace Phones\MainBundle\Controller\Admin;

use Phones\MainBundle\Controller\AppController,
    Symfony\Component\Security\Core\SecurityContext,
    Symfony\Component\HttpFoundation\Response;

class AdminController extends AppController {

    public function loginAction() {
        $request = $this->getRequest();
        $session = $request->getSession();

        $authErrorKey = SecurityContext::AUTHENTICATION_ERROR;
        if ($request->attributes->has($authErrorKey)) {
            $error = $request->attributes->get($authErrorKey);
        } else {
            $error = $session->get($authErrorKey);
            $session->clear($authErrorKey);
        }

        return $this->render(null, compact('error'));
    }

    public function indexAction() {
        return $this->render();
    }

    public function render($view = null, array $params = array(), Response $response = null) {
        if ($view === null) {
            $view = $this->getDefaultView();
        }

        $params = array_merge($params, array(
            'menu' => array(
                'Settings' => '/admin',
                'Brands'   => '/admin/brands',
                'Models'   => '/admin/models',
                'Logout'   => '/logout'
            )
        ));
        return parent::render($view, $params, $response);
    }

}